<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增首页轮播')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-carouselInfo-add">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">上传图片：</label>
            <div class="col-sm-8">
                <input id="imgFile" name="imgFile" class="file" type="file"  data-theme="fas" accept=".jpg,.img,.png">
            </div>
        </div>
        <!--<div class="form-group">
            <label class="col-sm-3 control-label is-required">跳转：</label>
            <div class="col-sm-8">
                <input name="toUrl" type="text" class="form-control">
            </div>
        </div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">排序号：</label>
            <div class="col-sm-8">
                <input name="sortNum" class="form-control" type="number" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input name="comments" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js" />
<script th:inline="javascript">

    var prefix = ctx + "web/carouselInfo";
    $("#form-carouselInfo-add").validate({
        onkeyup: false,
        rules:{
            sortNum:{
                minlength: 1,
                remote: {
                    url: prefix + "/checkSortNumUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "sortNum": function() {
                            return $.common.trim($("input[name='sortNum']").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            }
        },
        messages: {
            "sortNum": {
                remote: "排序号重复"
            }
        },
        focusCleanup: true
    });


    $("#imgFile").fileinput({
        uploadAsync:false,//默认异步上传
        showUpload:false,//是否显示上传按钮
        dropZoneEnabled: false,//是否显示拖拽区域，默认不写为true，但是会占用很大区域
    })

    function submitHandler() {
        if ($.validate.form()) {
            var formData = new FormData($("#form-carouselInfo-add")[0]);
            if ($('#imgFile')[0].files[0] != null) {
                formData.append('imgFile', $('#imgFile')[0].files[0]);
            }else {
                $.modal.alertError("未上传图片")
                return false;
            }
            $.ajax({
                url: prefix + "/add",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function (result) {
                    $.operate.successCallback(result);
                }
            });
        }
    }

</script>
</body>
</html>